package SGEngine

import (
	//"fmt"
	"github.com/gl"
)

type Quad struct {
	Node

	VBuffer  gl.Buffer
	MProgram *Program
	MColor   Color4
}

func NewQuad(Width, height float64) *Quad {
	RQuad := new(Quad)
	RQuad.Node = DefaultNode()
	RQuad.SetSize(Width, height, 1)
	RQuad.NodeRender = RQuad
	RQuad.MProgram = ACProgramMgr.GetProgram(PROGRAM_QUAD)
	RQuad.VBuffer = ACBufferMgr.GetVertexBuffer(BUFFER_Quad)
	return RQuad
}

func (q *Quad) Render() {
	q.MProgram.ProgramObject.Use()
	q.VBuffer.Bind(gl.ARRAY_BUFFER)
	q.MProgram.ProgramObject.GetUniformLocation("inColor").Uniform4f(q.MColor.R, q.MColor.G, q.MColor.B, q.MColor.A)
	q.MProgram.ProgramObject.GetAttribLocation("vPosition").AttribPointer(3, gl.FLOAT, false, 0, nil)
	q.MProgram.ProgramObject.GetAttribLocation("vPosition").EnableArray()
	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)
	q.VBuffer.Unbind(gl.ARRAY_BUFFER)

}
